﻿// Write an expression that extracts from a given integer i the value of a given bit number b.
// Example: i=5; b=2 -> value=1.

using System;

class ExtractBitOfGivenPosition
{
    static void Main()
    {
        Console.Write("Enter integer number: ");
        int number = int.Parse(Console.ReadLine());
        Console.Write("Enter position: ");
        int position = int.Parse(Console.ReadLine());

        int mask = 1;
        int maskPosition = mask << position;
        int numbAndMaskPosition = number & maskPosition;
        int bit = numbAndMaskPosition >> position;

        Console.WriteLine("The bit in position {0} has value {1}", position, bit);
    }
}
